
import { getGlobalMobile, setGlobalMobile } from '../entities/global'
import { getUserInfo, login, sendCode } from '../entities/user'

export class UserModel {
  isMock = false
  // 查询用户信息
  async getUserInfo(params) {
    if (this.isMock) {
      return {
        mobile: params.mobile,
        gwj: '100.00',
      }
    }
    const resp = await getUserInfo(params)
    if (resp.isSuccess) {
      return resp.data
    }
    throw new Error(resp.message)
  }
  // 发送验证码
  async sendSms(params) {
    const resp = await sendCode(params)
    if (resp.isSuccess) {
      return resp.data
    }
    throw new Error(resp.message)
  }
  // 登录
  async login(params) {
    const resp = await login(params)
    if (resp.isSuccess) {
      return resp.data
    }
    throw new Error(resp.message)
  }
  // 设置手机号
  setMobile(mobile) {
    setGlobalMobile(mobile)
  }
  // 获取手机号
  getMobile() {
    return getGlobalMobile()
  }
}